package com.zjhd.sealcutting.controller;

import com.zjhd.sealcutting.dto.SmsInfo;
import com.zjhd.sealcutting.service.SmsService;
import com.zjhd.sealcutting.utils.OperLog;
import com.zjhd.sealcutting.utils.response.ResponseResult;
import com.zjhd.sealcutting.utils.response.ResultGenerator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.slf4j.Logger;

/**
 * TODO  短信服务
 *
 * @author wangchao
 * @version 1.0
 * @date 2020/11/19 17:57
 */
@Api(value = "短信服务", tags = "短信服务")
@RequestMapping("/sms")
@RestController
public class SmsController {

    private final static Logger logger = LoggerFactory.getLogger(SmsController.class);

    @Autowired
    private SmsService smsService;

    @ApiOperation(value = "发送短信", notes = "发送短信")
    @PostMapping(value = "/sendSms")
    @OperLog(operModul = "短信管理-发送短信",operType = "新增",operDesc = "发送短信")
    public ResponseResult sendSms(@RequestBody SmsInfo smsInfo)throws Exception{
        try {
            return smsService.sendSms(smsInfo);
        }catch (Exception ex){
            logger.info("发送短信处理异常："+ex,this.getClass());
        }
        return ResultGenerator.genFailResult("发送失败");
    }

    @ApiOperation(value = "根据手机号获取最新短信验证码", notes = "根据手机号获取最新短信验证码")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "mobile",value = "手机号",dataType = "String" ,paramType = "query")
    })
    @GetMapping(value = "/queryMobileSmsVerificationCode")
    @OperLog(operModul = "短信管理-查询短信验证码",operType = "查询",operDesc = "根据手机号获取最新短信验证码")
    public ResponseResult queryMobileSmsVerificationCode(String mobile)throws Exception{
        try {
            return ResultGenerator.genSuccessResult(smsService.queryMobileSmsVerificationCode(mobile));
        }catch (Exception ex){
            logger.info("根据手机号获取最新短信验证码处理异常："+ex,this.getClass());
        }
        return ResultGenerator.genFailResult("获取短信验证码失败");
    }

}
